<?php

if (!defined('BASEPATH'))
	exit('No direct script access allowed');

class Users extends CI_Controller {

	function __construct() {
		parent::__construct();
		
	}
	
	/**
	 * 登陆
	 */
	function index()
	{
		$data['page_title'] = '登陆';
		$data['page_description'] = '登陆';
		$data['page_keywords'] = '登陆';
		
		$this->load->view('users/login_form',$data);		
	}
	
	function validate_credentials()
	{		
		
		$this->load->model('Users_model', '', TRUE);
		$query = $this->Users_model->validate();
		
		if($query) // if the user's credentials validated...
		{
			$data = array(
				'username' => $this->input->post('username'),
				'is_logged_in' => true
			);
			$this->session->set_userdata($data);
			redirect('/');
		}
		else // incorrect username or password
		{
			$this->index();
		}
	}
	
	function logout()
	{
		$this->session->sess_destroy();
		$this->index();
	}

}